<template>
  <div class="login-container">
    <el-form
      :model="ruleForm"
      status-icon
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <div class="login-title">
        <h3>Login Form</h3>
      </div>

      <el-form-item>
        <el-input
          type="text"
          prefix-icon="el-icon-user"
          v-model="ruleForm.username"
          autocomplete="off"
        />
      </el-form-item>

      <el-form-item>
        <el-input
          type="password"
          prefix-icon="el-icon-unlock"
          v-model="ruleForm.password"
          autocomplete="off"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width: 100%" @click.native.prevent="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        username: 'admin',
        password: '123456',
      },
      redirect: undefined
    };
  },
  methods:{
      handleLogin(){
          if(!this.ruleForm.username && !this.ruleForm.password) this.$message.error("输入正确的账号密码")
          this.$store.dispatch('user/login', this.ruleForm).then(res=>{
              this.$router.push({ path: this.redirect || '/'})
          }).catch((error)=>{
              reject(error)
          })
      }
  },
  watch: {
      $route: {
          handler: function(route){
              this.redirect = route.query && route.query.redirect
          },
          immediate: true
      }
  },
  created(){
    console.log("login",this.$route.matched);
  }
};
</script>
<style lang="scss">
$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

.login-container {
  .el-form-item__content {
    margin-left: 0 !important;
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
  .el-input {
    input {
      background: transparent;
      border: none;
      color: white;
    }
  }
}
</style>

<style lang="scss" scoped>
$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

.login-container {
  height: 100%;
  min-width: 60%;
  width: 100%;
  background: $bg;

  .el-form {
    padding: 160px 35px 0;
    margin: 0 auto;
    width: 520px;
    max-width: 100%;
    overflow: hidden;
  }
}
.login-title {
  position: relative;

  h3 {
    text-align: center;
    color: white;
    font-size: 28px;
    margin-bottom: 45px;
  }
}
</style>